<!-- 前端模板如下: -->
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加</title>
  <!-- 引入 layui.css -->
  <link href="{{ url_for('static', filename='lib/layui/css/layui.css')}}" rel="stylesheet">
</head>
<body>
<!-- 你的 HTML 代码 -->
<div class="layui-container" style="margin-top: 10px;">
    <div class="layui-row">
      <div class="layui-col-md8 layui-col-md-offset2">
          <form class="layui-form layui-form-pane">
			  <input type="hidden" name="id" id="id"/>
            <div class="layui-form-item">
              <label class="layui-form-label">组别</label>
              <div class="layui-input-inline">
                <select id ="module" name="module" lay-filter="aihao">
                  {% if modules %}
                  {% for module in modules %}
                  <option value="{{module.module}}">{{module.module}}</option>
                  {% endfor %}
                  {% endif %}
                  <!-- <option value=""></option>
                  <option value="0">小组1</option>
                  <option value="1" selected>小组2</option>
                  <option value="2">小组3</option>
                  <option value="3">小组4</option>
                  <option value="4">小组5</option> -->
                </select>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">设备ID</label>
              <div class="layui-input-block">
                <input type="text" id="name" name="name" autocomplete="off" placeholder="请输入设备ID" lay-verify="required" class="layui-input">
              </div>
            </div>
            <!-- <div class="layui-form-item">        
                <label class="layui-form-label">报警日期</label>
                <div class="layui-input-block">
                  <input type="text" class="layui-input" name="create_time" autocomplete="off" placeholder="yyyy-MM-dd">
                </div>
            </div> -->
			<div class="layui-form-item">
			    <div class="layui-inline">
			        <label class="layui-form-label">报警时间</label>
			        <div class="layui-input-inline">
			            <input type="text" class="layui-input" name="create_time" id="create_time"
			                    placeholder="" autocomplete="off" lay-verify="required">
			        </div>
			    </div>
			</div>
            <div class="layui-form-item">
              <label class="layui-form-label">报警次数</label>
              <div class="layui-input-block">
                <input type="text" id="value" name="value" autocomplete="off" placeholder="请输入报警次数" lay-verify="required" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <button class="layui-btn" lay-submit lay-filter="edit">更新</button>
              <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
          </form>
      </div>
    </div>
</div>


<!-- 引入 layui.js -->
<script src="{{ url_for('static', filename='lib/layui/layui.js') }}" charset="utf-8"></script>
<script>
    layui.use(function(){
      //时间控件
      var $ = layui.$;
	  var layer = layui.layer ;
	  var form = layui.form;
	  var laydate = layui.laydate;
	  

	  // 渲染时间选择器
	  laydate.render({
	  	 elem: '#create_time',  
	  });	
	  
	  form.on("submit(edit)",function(obj){
		  var field = obj.field; // 获取表单字段值
		  console.log("field",(field))
		  console.log(("id:",field.id))
		  
		  
		  $.ajax({
			  url: '/api/equipment/edit/'+ field.id,
			  type: 'POST',
			  data:JSON.stringify(field),
			  contentType:"application/json",
			  success: function(d){
				  layer.msg("更新成功");
				  //parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
				  var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
				  parent.layer.close(index); // 再执行关闭
				  //parent.layui.table.reload('test');
			  },
		  })
		   return false; // 阻止默认 form 跳转
	  });
	  
    });

</script>

</body>
</html>